<template>
  <div>
    <div class="hearder-search">
      <div class="breadcrumb-container">
        <div class="search_box">
          <el-input v-model="searWord.realname" placeholder="姓名" size="small"
                    class="w-140"></el-input>
        </div>
        <el-button type="primary" @click="searchBtn" size="small"><i class="el-icon-search"></i>搜索</el-button>
        <el-button size="small" @click="refreshFn"><i class="el-icon-refresh"></i>刷新</el-button>
        <downexcel type="teacher_user_leave" :option="{type: 0}"></downexcel>
        <el-button size="small" @click="leavCodeVisible=true">教职工离厦申报二维码</el-button>
        <span class="allbook">总 {{ page.total }} 条数据</span>
      </div>

    </div>
    <!--本体列表，数据 -->
    <div class="table-body">
      <div class="table-body-box">
        <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableoption.tableStripe"
            :border="tableoption.tableBorder"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              prop="name"
              label="姓名">
            <template slot-scope="scope">
              {{ scope.row.user?scope.row.user.realname:'' }}
            </template>
          </el-table-column>
          <el-table-column
              prop="create_time"
              label="申报日期"
              width="100">
          </el-table-column>
          <el-table-column
              prop="address"
              label="外出目的地">
          </el-table-column>
          <el-table-column
              prop="reason"
              label="外出事由"
              width="100">
          </el-table-column>
          <el-table-column
              label="离厦居住方式">
            <template slot-scope="scope">
              {{ scope.row.live_type == 1 ? '居家' : '酒店' }}
            </template>
          </el-table-column>
          <el-table-column
              prop="start_time"
              label="离厦日期">
          </el-table-column>
          <el-table-column
              prop="end_time"
              label="返厦日期">
          </el-table-column>
          <el-table-column
              prop="description"
              label="交通工具">
            <template slot-scope="scope">
              {{vehicleList[scope.row.vehicle]}}
            </template>
          </el-table-column>
          <el-table-column
              prop="leaveOther"
              label="中途是否逗留其他城市">
          </el-table-column>
          <el-table-column
              label="操作"
              width="140">
            <template slot-scope="scope">
              <el-button size="small" @click="addActive(scope.row.id)">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!--工具条 分页-->
    <el-col :span="24" class="toolbar">
      <el-pagination
          background
          :page-size="page.pagesize"
          :current-page="page.pageindex"
          layout="total, prev, pager, next"
          :total="page.total"
          @current-change="handleSizeChange"></el-pagination>
    </el-col>
    <!--    type 1 学生 2 职工-->
    <!--    <healthstudent :visible.sync="healthstudentvisible" type="2"></healthstudent>-->
    <historyList :visible.sync="historyvisible" type="1"></historyList>
    <!--    未申报人数 type 1 学生 2 职工-->
    <notSubmit :visible.sync="healthstudentvisible" type="2"></notSubmit>
    <!--    type 1 学生 2 职工-->
    <healthEdit :visible.sync="healthdetailvisible" :healthId="healthId" type="2"></healthEdit>
    <applyCode :visible.sync="leavCodeVisible" type="0"></applyCode>
  </div>
</template>

<script>
import {pagination, tableoption, yearDay} from '@/utils/util.js'
import historyList from "../popup/historyList";
import notSubmit from "../popup/notSubmit";
import healthEdit from "../popup/leaveDetail";
import {leaveIndex} from '@/api/admin/trajectory.js'
import applyCode from "../popup/applyCode";

export default {
  components: {
    historyList,
    notSubmit,
    healthEdit,
    applyCode
  },
  data() {
    return {
      leavCodeVisible: false,
      tableoption: tableoption,
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [], // 数据列表
      // 搜索
      searWord: {
        realname: '',
        type: 0
      },
      value1: '',
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() > Date.now() + 8.64e7
        }
      },
      // 是否健康
      isHealth: [
        {
          id: 1,
          name: '是'
        },
        {
          id: 0,
          name: '否'
        }
      ],
      isHealthOther: [
        {
          id: 1,
          name: '是'
        },
        {
          id: 0,
          name: '否'
        }
      ],
      temperatureList: [
        {
          id: 1,
          name: '是'
        },
        {
          id: 0,
          name: '否'
        }
      ],
      downloadOption: {
        name: '',
        is_green: '', // 是否绿吗
        is_other_green: '',
        is_temperature: '',
        start_time: '',
        end_time: '',
        type: 1
      },
      healthstudentvisible: false,
      teacherNumber: 0,
      historyvisible: false, // 历史记录
      healthdetailvisible: false,
      healthId: 0,
      statusLine: 0,
      statusList: [{name: '全部', id: 0}, {name: '是', id: 1}, {name: '否', id: 2}], // 已读状态
      vehicleList: {
        1: '自驾',
        2: '动车/火车',
        3: '飞机',
        4: '大巴',
        5: '轮船'
      }
    }
  },
  created() {
    // this.searWord.end_time = this.dealTime(9)
    this.InitFn()
  },
  methods: {
    // 初始化
    InitFn() {
      let option = JSON.parse(JSON.stringify(this.searWord))
      option.p = this.page.pageindex
      leaveIndex(option).then(res => {
        if (!res.code) {
          for(let item of res.list.data){
            item.create_time = item.create_time.split(' ')[0]
            item.leaveOther = item.log?'有':'无'
          }
          this.arryList = res.list.data
          this.page.total = res.list.total
        }
      })
      // this.$post(this.api.manage.health.index, option).then((response) => {
      //   if (response.code === 0) {
      //     for (let i in response.list.data) {
      //       response.list.data[i].create_time = yearDay(response.list.data[i].create_time)
      //     }
      //     this.arryList = response.list.data
      //     this.page.total = response.list.total
      //     this.teacherNumber = response.user
      //   } else {
      //   }
      // }).catch((err) => {
      //   console.log(err)
      // })
    },
    gotohistory() {
      this.historyvisible = true
      // this.$router.push('/historyindex?type=' + 1)
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    handleSelectionChange(val) {
      this.handleSelection = val
    },
    // 搜索
    searchBtn() {
      this.page.pageindex = 1
      if (this.value1) {
        this.searWord.start_time = this.value1[0]
        this.searWord.end_time = this.value1[1]
      } else {
        this.searWord.start_time = ''
        this.searWord.end_time = ''
      }
      this.searWord.start_time = this.dealTime(6)
      this.InitFn()
    },
    addActive(id) {
      this.healthId = id;
      this.healthdetailvisible = true;
      // this.$router.push('/healthEdit?id=' + id)
    },
    // 刷新页面
    refreshFn() {
      this.page.pageindex = 1
      this.searWord.realname = ''
      this.InitFn()
    },
    // 查看未申报人
    checkUserHealth() {
      this.healthstudentvisible = true
    },
    dealTime(v) {
      let b = 24 * 60 * 60 * 1000   //一天的时间
      let day = new Date();  //当天的时间
      v == 3 ? day.setTime(day.getTime() - b) : v == 6 ?
          day.setTime(day.getTime()) : day.setTime(day.getTime() + b);

      let dayMon = (day.getMonth() + 1) >= 10 ? day.getMonth() + 1 : '0' + (day.getMonth() + 1)
      let dayDat = (day.getDate() + 1) >= 10 ? day.getDate() : '0' + (day.getDate())

      let s = day.getFullYear() + "-" + dayMon + "-" + dayDat;
      return s
    }
  },
  mounted() {
  }
  // 缓存机制 end
}
</script>
<style scoped>
.allbook i {
  font-style: normal;
  color: red;
}

.allbook em {
  font-style: normal;
}

.allbook em:hover {
  text-decoration: underline;
  cursor: pointer;
}
</style>
